//
//  OrderSuccessView.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2022/10/11.
//

import SwiftUI

struct OrderSuccessView: View {
   @Binding var state: EnumCurrentState
   var body: some View {
       GeometryReader { geometry in
           VStack {
               Spacer()
               VStack {
                   VStack(alignment: .center) {
                       Image("banner").resizable().scaledToFit()
                       Text("感谢您的一路陪伴，下次再见！").foregroundColor(.black).padding()
                   }.padding()
                   Button {
                       print("cancel...")
                       clear()
                   } label: {
                       Text("OK").foregroundColor(.white)
                   }
                   .frame(width: 320, height: 40)
                   .padding()
                   .background(
                    RoundedRectangle(cornerRadius: 10.0)
                        .fill(Color(hex: "FF862F8D"))
                        .padding()
                   )
               }.frame(width: geometry.size.width)
                   .background(.white)
                   .cornerRadius(10)
                   .shadow(radius: 8)
                   .onAppear() {
                       DispatchQueue.main.async {
                           self.state = .none
                           CarOrder.shared.clear()
                           CarOrder.shared.startPos = ViewModel.shared.lastLocation
//                           CarOrder.shared.startLabel = "\("出发地：\("自动定位")".localized())"
//                           CarOrder.shared.endPos = nil
//                           CarOrder.shared.endLabel = ""
                           MapConfig.shared.startOrEndChanged = true
                       }
                   }
           }
       }
   }

   func clear() {
      DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
         self.state = .none
         CarOrder.shared.clear()
      }
   }
}

// struct OrderSuccessView_Previews: PreviewProvider {
//    static var previews: some View {
//      OrderSuccessView()
//    }
// }
